
// document.write("<script language=javascript src='./js/api.js'></script >");
document.write("<script language=javascript src='../sourceControl/js/api.js'></script >");
var siteId = ""
var beginTime = ""
var endTime = ""
var detailObj = {
  devid: [],
  index: 0,
  dataArr: [],
  plateColor: "",
  bool: 0,
  bool2: 0,
  bool3: 0,
  ztcdevid: '',
  deviceIds: [],
  page: 1,
  dwData1: []
}
GetRequest()
getSateImg()
function GetRequest () {
  var url = location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  siteId = theRequest.devid
  beginTime = theRequest.date + ' 00:00:00'
  endTime = theRequest.date + ' 23:59:59'
}

var vehicleList = [] //车辆数组
var path = [] //路线
var bm = new BMap.Map("container", { minZoom: 11, maxZoom: 18, enableMapClick: false })//设置最大和最小缩放级别);
bm.centerAndZoom(new BMap.Point(116.228893, 40.02077), 11);//初始化显示级别和位置
bm.enableScrollWheelZoom();//开启滚动缩放地图
var mapStyle = {
  style: "midnight"
};
bm.setMapStyle(mapStyle);
var bdary = new BMap.Boundary();
bdary.get("北京市海淀区", function (rs) {       //获取行政区域
  var xcq = new BMap.Polygon(rs.boundaries[0], {
    strokeWeight: 2,
    strokeColor: "#41b0fd",
    strokeStyle: "solid",
    fillOpacity: 0.2,
    fillColor: "#0053A9"
  }); //建立多边形覆盖物
  bm.addOverlay(xcq);
  xcq.disableMassClear();
});

//调取地图
// function getFetchMap () {
  // var bm = new BMap.Map("container", { minZoom: 11, maxZoom: 18, enableMapClick: false })//设置最大和最小缩放级别);
  // bm.centerAndZoom(new BMap.Point(116.228893, 40.02077), 11);//初始化显示级别和位置
  // bm.enableScrollWheelZoom();//开启滚动缩放地图
  // var mapStyle = {
  //   style: "midnight"
  // };
  // bm.setMapStyle(mapStyle);
  // var bdary = new BMap.Boundary();
  // bdary.get("北京市海淀区", function (rs) {       //获取行政区域
  //   var xcq = new BMap.Polygon(rs.boundaries[0], {
  //     strokeWeight: 2,
  //     strokeColor: "#41b0fd",
  //     strokeStyle: "solid",
  //     fillOpacity: 0.2,
  //     fillColor: "#0053A9"
  //   }); //建立多边形覆盖物
  //   bm.addOverlay(xcq);
  //   xcq.disableMassClear();
  //   var point = new BMap.Point(116.2163491, 40.0941961);
  //   var marker = new BMap.Marker(point);        // 创建标注   
  //   bm.addOverlay(marker);

  // var content = "<div style='color:#D4E9FF;'>车牌号:<span>京A394850</span></div>";
  // var label = new BMap.Label(content, {       // 创建文本标注
  //   position: point,                          // 设置标注的地理位置
  //   offset: new BMap.Size(10, 20)           // 设置标注的偏移量
  // })
  // bm.addOverlay(label);                        // 将标注添加到地图中
  // label.setStyle({                              // 设置label的样式
  //   color: '#D4E9FF',
  //   fontSize: '12px',
  //   backgroundColor: '#00C6FF',
  //   border: '2px solid #00C6FF'
  // })
  // let newPath = []
  // path.forEach(item=>{
  //   newPath = newPath.push(new BMap.Point(item.lng, item.lat))
  // })
  // console.log(newPath)
  // var polygon = new BMap.Polygon(newPath, { strokeColor: "blue", strokeWeight: 2, strokeOpacity: 0.5 });
  // bm.addOverlay(polygon);
  // var p1 = new BMap.Point(116.2163491, 40.0941961);
  // var p2 = new BMap.Point(116.404, 39.915);

  // var driving = new BMap.DrivingRoute(bm, { renderOptions: { map: bm, autoViewport: true } });
  // driving.search(p1, p2);
  //设置图片
  // var myIcon = new BMap.Icon("./images/qishitu.png", new BMap.Size(50, 50), {
  //   // anchor: new BMap.Size(10, 25),
  //   // imageOffset: new BMap.Size(0, 0 - 25)   // 设置图片偏移   
  // });
  // // 创建标注对象并添加到地图  
  // var marker = new BMap.Marker(point, { icon: myIcon });
  // bm.addOverlay(marker); 

  // });
// }
//视频专网绘制海淀区轮廓
function displayData (results) {
  var result = results[0];
  var xysArr = result.boundary.split(';');
  var points = [];
  $.each(xysArr, function (i, xy) {
    var xyArr = xy.split(',');
    points.push(new BMap.Point(xyArr[0], xyArr[1]));
  });
  var polygon = new BMap.Polygon(points, {
    strokeWeight: 5,
    strokeColor: "#22e5f9",
    strokeStyle: "solid",
    fillOpacity: 0.1,
    fillColor: "#22e5f9"
  });
  bm.addOverlay(polygon);
  polygon.disableMassClear();
}

function getSateImg () {
  let JSCparam = {
    page: 1,
    rows: 10,
    siteId: siteId,
    month: '202202'
  }
  index_port('GET', api.getStaeImg, JSCparam, function (res) {
    console.log(res)
    var html = ``
    res.list.forEach(item => {
      html = html + `<div class="img_map">
          <img src="${item.SITE_SATELLTEROCKERIMAGE_URL}" alt="">
          <span>${item.CREATEDATE} 拍摄</span>
        </div>`
    })
    $("#tupian").append(html)
  })
}
//获取群众举报
function getReport () {
  let param = {
    siteId: siteId,
  }
  sendAjax('GET', api.findJSCBBySiteIdForPage, param, function (res) {
    res.forEach(item => {
      $("#detail_content").append(`<div><label> ${item.LETTERTIME}</label><span>${item.CONTENTS}</span></div>`);
    })

  })
}
// 车辆数
function getVehicleInfo () {
  let param = {
    beginTime: beginTime,
    endTime: endTime,
    siteID: siteId,
    carNum: '1',
    siteStatus: '',
    street: ''
  }
  sendAjax('GET', api.findMuckInSiteByTime, param, function (res) {
    let newList = res.list[0].PLATE_NO.split(",")
    vehicleList = newList
    newList.forEach((item, index) => {
      $("#vehicleInfo").append(`<span onclick=distance(${index})>${item}</span>`)
    })
    distance(0)
  })
}
// 点击事件
function distance (num) {
  bm.clearOverlays()
  let param = {
    carType: 2,
    beginTime: beginTime,
    endTime: endTime,
    plateNo: vehicleList[num],
    page: 1,
    rows: 24,
  }
  otherAjax('GET', api.queryCar, param, function (res) {
    if (res.rows.length === 0) {
      return false
    }
    res.rows.forEach(item => {
      path = [...path, ...[new BMap.Point(item.SS_APE_LONGITUDE, item.SS_APE_LATITUDE)]]
    })
    var newArrs = res.rows
    var points = [path[0], path[path.length - 1]];
    var markers = [new BMap.Marker(points[0]), new BMap.Marker(points[1])];
    bm.addOverlay(markers[0]);
    bm.addOverlay(markers[1]);
    newArrs.forEach((item, index) => {
      path = [...path, ...[new BMap.Point(item.SS_APE_LONGITUDE, item.SS_APE_LATITUDE)]]
      if (index < newArrs.length) {
        var startpoint = {
          lat: item.SS_APE_LATITUDE,
          lng: item.SS_APE_LONGITUDE
        }
        var endpoint = {
          lat: newArrs[index + 1].SS_APE_LATITUDE,
          lng: newArrs[index + 1].SS_APE_LONGITUDE
        }
        luxianInof(startpoint, endpoint)
      }
    })
    // var polygon = new BMap.Polyline(path, { strokeColor: "#13FFFF", strokeWeight: 3, strokeOpacity: 0.9 });
    // bm.addOverlay(polygon);
    // console.log(path)
  })
}
//点与点之前的坐标集合 
//路线规划
function luxianInof (startpoint, endpoint) {
  $.ajax({
    type: 'get',
    dataType: "json",
    data: {
      httpurl: "/cloudsearch?output=json&index=direction&action=route&origin=" + startpoint.lat + "," + startpoint.lng +
        "&destination=" + endpoint.lat + "," + endpoint.lng + "&waypoints=&mode=CAR"
    },
    url: "http://11.16.127.79:5013/VIAS/web/snapshot/baidu/RectangleRetrievel",
    success: function (data) {
      if (data.message == "ok") {
        var pointlist = data.results[0].path.split(",");
        var point = [];
        for (var i = 0; i < pointlist.length; i += 2) {
          point.push(new BMap.Point(pointlist[i], pointlist[i + 1]));
        }
        var polyline = new BMap.Polyline(point, {
          strokeColor: "#13FFFF",
          strokeWeight: 3,
          strokeOpacity: 0.9
        });
        bm.addOverlay(polyline);
        // chtygjList[id].push(polyline);
      }
    }
  })
}

//获取坐标中心值 和四周坐标值
function getsatelliteMap () {
  // let param = {
  //   buildingSiteNum: ''
  // }

  // satelliteAjax('GET', api.getBuildSiteInfo, param, function (res) {
  //   console.log(res, '中心点')
  // })
}
// 出入口抓怕list
function getSnapshotList () {
  let devObj = {
    siteId: siteId
  }
  otherAjax('GET', api.getDevId, devObj, function (res) {
    let param = {
      page: 1,
      rows: 100,
      deviceId: res.deviceId,
      beginTime: beginTime,
      endTime: endTime,
      JXX: false,
      sourceID: ''
    }
    getVehicleNum(param)
  })


}
function getVehicleNum (param) {
  otherAjax('GET', api.findByMuckTruckLeaderUse, param, function (res) {
    var html = ""
    res.rows.forEach((item) => {
      var IFViolation = IFVehicle(item.SS_PLATE_NO_PLATE_COLOR, item.PASS_TIME)
      var IFViolationHtml = ''
      !IFViolation ? IFViolationHtml = '<span class="right red">违规</span>' : IFViolationHtml = ' <span class="right blue">合格</span>'
      IFEvent(item.PASS_TIME, item.SS_ID)
      html = `<div class="img_map swiper-slide" onClick="showmotor('${item.SS_ID}','${item.PASS_TIME}','${item.DEVICE_ID},${beginTime}','0','${item.SS_PLATE_NO_PLATE_COLOR}','${item.PLATE_COLOR}')">
        <div class="top">
          <img src="${item.STORAGE_URL1}" alt="">
            <span class="left">已受理</span>
           ${IFViolationHtml}
        </div>
        <div class="bottom">
          <div>
            <label>时间：</label>${item.PASS_TIME}
          </div>
          <div>
            <label>地点：</label>${item.SS_APE_NAME}
          </div>
          <div>
            <label>车牌：</label>${item.SS_PLATE_NO_PLATE_COLOR}
          </div>
        </div>
      </div>`
      $("#pictureID").append(html)
    })
  })
}
// 判断出入口抓拍是否违规
function IFVehicle (ch, passTime) {
  let param = {
    ch: ch, //车牌号
    passTime: passTime //经过时间
  }
  var chIF = false
  otherAjax('GET', api.VehicleZYZBycph, param, function (res) {
    if (res.length > 0) {
      chIF = true
    }
  })
  return chIF
}
// 判断是否受理
function IFEvent (time, id) {
  let param = {
    PASS_TIME: time,
    SS_ID: id
  }
  var CASESTATE = ''
  EventAjax('GET', api.isSaveEvent, param, function (res) {
    CASESTATE = res[0].CASESTATE
  })
}


//一车一档详情
function showmotor (ssid, time, device_id, beginTime, obj, plateNo, plateColor) {
  var parma = '?ssid=' + encodeURIComponent(ssid) +
    '&time=' + encodeURIComponent(time) +
    '&deviceId=' + encodeURIComponent(device_id) +
    '&beginTime=' + encodeURIComponent(beginTime) +
    '&plateNo=' + encodeURIComponent(plateNo) +
    '&plateColor=' + encodeURIComponent(plateColor) +
    '&parentObj=detailObj';
  detailObj.index = obj;
  detailObj.plateColor = plateColor;
  layui.use('layer', function () {
    var layer = layui.layer;
    layer.open({
      type: 2,
      fixed: true,
      title: ['一车一档详情', 'font-size: 22px;color: rgb(49, 70, 89);'],
      closeBtn: 1,
      scrollbar: false,
      maxmin: false,
      content: '/vias_app/views/vias/snapshot/ztc/oneCarToInfo.html' + parma,
      area: ['100%', '100%'],
      end: function () {
        // 暂时不用
      }
    });
  });
}

